<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="s_type" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 添加关系 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="关联类型" prop="">
              {{getValueName("产品关联=1,供应商关联=2,外购件关联=3",s_type.link_module_id)}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="关联项" prop="related_name">
              <el-input v-model="s_type.related_name" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="关联至" prop="">
              {{s_type.link_item_id}}
              <!--选择产品-->： {{s_type.link_item_id}}
              <el-button @click="popRelationProductChoice('','link_item_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
              <!--选择外购件-->： {{s_type.link_item_id}}
              <el-button @click="popRelationProductChoice('','link_item_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="relationAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>建立关系</el-button>
      <el-button @click="gotoPage('/crm/sale/Relation?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
    </el-form>
    <el-dialog :visible.sync="RelationProductChoiceVisible" append-to-body>
      <RelationProductChoice v-if="RelationProductChoiceVisible" ref="RelationProductChoice" :popparams="popparams"> </RelationProductChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import RelationProductChoice from "@/views/crm/sale/RelationProductChoice";
  export default {
    name: 'RelationAdd',
    components: {
      RelationProductChoice,
    },
    props: ['popparams'],
    data() {
      return {
        RelationProductChoiceVisible: false,
        RelationProductChoiceValue: null,
        RelationProductChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        s_type: {
          link_module_id: null,
          related_name: null,
          link_item_id: null,
          link_item_id: null,
          link_item_id: null,
        },
        loading: false,
        rules: {}
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/CustomerAction/relationAdd?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      relationAddSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/CustomerAction/relationAddSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/Relation/relation?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popRelationProductChoice(desc, value) {
        this.RelationProductChoiceVisible = true;
        this.RelationProductChoiceDesc = desc;
        this.RelationProductChoiceValue = value;
      },
      closeRelationProductChoice(value, desc) {
        this.RelationProductChoiceVisible = false;
        this.$set(this.s_type, this.RelationProductChoiceDesc, desc);
        this.$set(this.s_type, this.RelationProductChoiceValue, value);
      },
    },
  }
</script>
